<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>清除倒计时</title>
	</head>
	<body>
		<button class="begin">启动计时器</button>
		<button class="clear">清除计时器</button>
		
		<script type="text/javascript">
			window.addEventListener('load',function() {
				//获取按钮
				var begin = document.querySelector('.begin');
				var clear = document.querySelector('.clear');
				
				//定时器标识
				var timer = null;
				begin.addEventListener('click',function() {
					//启动计时器,每隔一秒打印一次
					timer = setInterval(function() {
						console.log('开始打印')
					},1000)
				});
				
				//清除定时器
				clear.addEventListener('click',function() {
					clearInterval(timer);
				})
			})
		</script>
	</body>
</html>
